const express = require('express');
const router = express.Router();
const materialController = require('../controllers/materialController');

/**
 * @swagger
 * tags:
 *   name: 材料管理
 *   description: 材料信息的增删改查 API
 */

/**
 * @swagger
 * /api/materials:
 *   get:
 *     summary: 获取所有材料
 *     tags: [材料管理]
 *     responses:
 *       200:
 *         description: 返回材料列表
 */
router.get('/', materialController.getAll);

/**
 * @swagger
 * /api/materials/{id}:
 *   get:
 *     summary: 获取指定ID的材料信息
 *     tags: [材料管理]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *     responses:
 *       200:
 *         description: 材料详情
 */
router.get('/:id', materialController.getById);

/**
 * @swagger
 * /api/materials:
 *   post:
 *     summary: 创建新的材料记录
 *     tags: [材料管理]
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               name:
 *                 type: string
 *               code:
 *                 type: string
 *               specification:
 *                 type: string
 *               supplier:
 *                 type: integer
 *               project:
 *                 type: integer
 *               warehouse:
 *                 type: integer
 *               type:
 *                 type: integer
 *               cost:
 *                 type: number
 *               unit:
 *                 type: string
 *     responses:
 *       200:
 *         description: 创建成功
 */
router.post('/', materialController.create);

/**
 * @swagger
 * /api/materials/{id}:
 *   put:
 *     summary: 更新材料信息
 *     tags: [材料管理]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *     responses:
 *       200:
 *         description: 更新成功
 */
router.put('/:id', materialController.update);

/**
 * @swagger
 * /api/materials/{id}:
 *   delete:
 *     summary: 删除材料（软删除）
 *     tags: [材料管理]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *     responses:
 *       200:
 *         description: 删除成功
 */
router.delete('/:id', materialController.delete);

module.exports = router;
